package com.zsrt.java.ex.reflect.reflect02;

import static org.junit.Assert.*;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.junit.Test;

public class test2 {
	
	@Test
	public void testName() throws Exception {
		Class<?> clazz=Class.forName("com.zsrt.java.ex.reflect.reflect01.Person");
		Field numField=clazz.getDeclaredField("num");
		System.out.println(numField);
		//获得构造函数
		Constructor constructor=clazz.getDeclaredConstructor();
		//获得对象
		Object obj=constructor.newInstance();
		numField.setAccessible(true);
		
		numField.set(obj, 1001);
		System.out.println(obj);
		
		
	}
	
	
	@Test
	public void testMother() throws Exception {
		Class clazz=Class.forName("com.zsrt.java.ex.reflect.reflect01.Person");
		Constructor constructor=clazz.getConstructor();
		Object obj = constructor.newInstance();
		
		Method method=clazz.getDeclaredMethod("info");
		method.invoke(obj);
		
		Method method2=clazz.getDeclaredMethod("info", String.class);
		
		method2.setAccessible(true);
		method2.invoke(obj,"刘浩");
		
		
		
		
		
		
		
		
		
		
		
		
	}
}
